package gew.html;

import gew.utils.SqlUtils;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Scanner;

public class HtmlTemplates {

    public final static String INDICATORS_GRAPH = HtmlTemplates.class
            .getResource("indicators_graph_balloon_template.html").getPath();
    public final static String TRADE_GRAPH_BALLOON_TEMPLATE = HtmlTemplates.class
            .getResource("trade_graph_balloon_template.html").getPath();

    private final static HashMap<String, String> templates = new HashMap<>();

    public static String getTemplate(String key) {
        if (!templates.containsKey(key)) {
            initTemplate(key);
        }
        return templates.get(key);
    }

    private static void initTemplate(String key) {
        String t = "";
        try (Scanner in = new Scanner(new FileReader(key))) {
            while (in.hasNext()) {
                t = t.concat(SqlUtils.SPACE).concat(in.next());
            }
        } catch (Exception e) {
            t = "";
        }
        templates.put(key, t);
    }
}
